﻿Imports System.Data.OleDb

Partial Public Class ShareIdeas
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub



    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim Titleconn = New OleDbConnection(ConfigurationManager.ConnectionStrings _
                   ("ConnectionString").ToString())
        Titleconn.Open()

        Dim newTitleSql As String = "Insert INTO DiscussionShareMain (DiscussionName) VALUES (@DiscussionName)"
        Dim newTagCmd As New OleDbCommand(newTitleSql, Titleconn)
        newTagCmd.Parameters.AddWithValue("@DiscussionName", txtTitle.Text)
        newTagCmd.ExecuteNonQuery()

        Dim idOfNewTitle = txtTitle.Text

        Dim findTitleSql As String = "SELECT TOP 1 ID From DiscussionShareMain ORDER BY ID Desc"
        Dim findTitleCmd As New OleDbCommand(findTitleSql, Titleconn)
        Dim dbread As OleDbDataReader = findTitleCmd.ExecuteReader
        dbread.Read()
        Dim idOfNewTitle1 = dbread("ID")

        Dim discussionShareSql As String = "INSERT INTO DiscussionShare (DiscussionTitle,Body,UserName,PostedDate) VALUES(@DiscussionTitle,@Body,@UserName,@PostedDate)"
        Dim discussionSharecmd As New OleDbCommand(discussionShareSql, Titleconn)
        discussionSharecmd.Parameters.AddWithValue("@DiscussionTitle", idOfNewTitle1)
        discussionSharecmd.Parameters.AddWithValue("@Body", txtBody.Text)
        discussionSharecmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        discussionSharecmd.Parameters.AddWithValue("@PostedDate", DateTime.Now.Date)

        discussionSharecmd.ExecuteNonQuery()
        Response.Redirect("ShareIdeas.aspx")

    End Sub
End Class